/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.storage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 售后Controller
 */
@RestController(value = "apiorderservice")
@RequestMapping(value = "/api/order/service")
public class ServiceController extends APIController {

    @Autowired
    private OrderService orderService;

    /**
     * 会员售后
     * @param transMemberId 转发会员Id
     * @param memberId 会员Id
     * @param identity 标识【all全部 waiting待处理 processing处理中 complete已完成 reject已驳回】
     * @param size 每页数量
     * @param page 页码
     * @return 售后处理列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "query")
    @ResponseBody
    public ServerResponse<List<Map>> query(@RequestParam(value="transMemberId",required = false) String transMemberId,@RequestParam(value="memberId") String memberId,@RequestParam(value="identity") String identity, @RequestParam(value="size",defaultValue = "5") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page)
    {
        return  ServerResponse.createBySuccess(200,orderService.getServiceListByMemberId(transMemberId,memberId,identity, size,page));
    }

    /**
     * 售后处理
     * @param memberId 会员Id
     * @param identity 标识【all全部 waiting待处理 processing处理中 complete已完成 reject已驳回】
     * @param size 每页数量
     * @param page 页码
     * @return 售后处理列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "handle/query")
    @ResponseBody
    public ServerResponse<List<Map>> handleQuery(@RequestParam(value="memberId") String memberId,@RequestParam(value="identity") String identity, @RequestParam(value="size",defaultValue = "5") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page)
    {
        return  ServerResponse.createBySuccess(200,orderService.getHandleListByMemberId(memberId,identity, size,page));
    }

    /**
     * 售后发起
     * @param memberId 会员Id
     * @param orderId 订单Id【订单】
     * @return 售后发起【内容】
     */
    @RequestMapping(method = RequestMethod.GET,value = "form")
    @ResponseBody
    public ServerResponse<Map> form(@RequestParam(value="memberId") String memberId,@RequestParam(value="orderId") String orderId)
    {
        return  ServerResponse.createBySuccess(200,orderService.getServiceFormById(memberId, orderId));
    }

    /**
     * 售后提交
     * @param orderId 订单Id【订单】
     * @param type 类型
     * @param goods 商品
     * @param images 凭证
     * @param reason 原因
     * @return 售后提交
     */
    @RequestMapping(method = RequestMethod.POST,value = "submit")
    @ResponseBody
    public ServerResponse<String> submit(@RequestParam(value="orderId") String orderId,@RequestParam(value="type") String type,@RequestParam(value="goods") String goods,@RequestParam(value="images") String images,@RequestParam(value="reason") String reason)
    {
        Integer code = orderService.serviceSubmit(orderId, type,getJsonParam(goods),getJsonParam(images),reason);
        switch (code){
            case 200:
                return  ServerResponse.createBySuccess(code,"提交成功");
            default:
                return  ServerResponse.createBySuccess(code,"发生其它异常");
        }
    }

    /**
     * 代理审核【同意】
     * @param orderId 订单Id【订单】
     * @return 代理审核
     */
    @RequestMapping(method = RequestMethod.POST,value = "agree")
    @ResponseBody
    public ServerResponse<String> agree(@RequestParam(value="orderId") String orderId)
    {
        Integer code = orderService.agentAudit(orderId, "同意",null);
        switch (code){
            case 200:
                return  ServerResponse.createBySuccess(code,"审批完成");
            default:
                return  ServerResponse.createBySuccess(code,"发生其它异常");
        }
    }

    /**
     * 代理审核【拒绝】
     * @param orderId 订单Id【订单】
     * @param reason 原因
     * @return 代理审核
     */
    @RequestMapping(method = RequestMethod.POST,value = "reject")
    @ResponseBody
    public ServerResponse<String> reject(@RequestParam(value="orderId") String orderId,@RequestParam(value="reason") String reason)
    {
        Integer code = orderService.agentAudit(orderId, "拒绝",reason);
        switch (code){
            case 200:
                return  ServerResponse.createBySuccess(code,"审批完成");
            default:
                return  ServerResponse.createBySuccess(code,"发生其它异常");
        }
    }

    /**
     * 售后详情
     * @param orderId 订单Id【订单】
     * @return 售后详情
     */
    @RequestMapping(method = RequestMethod.GET,value = "content")
    @ResponseBody
    public ServerResponse<Map> content(@RequestParam(value="orderId") String orderId)
    {
        return  ServerResponse.createBySuccess(200,orderService.getServiceContentById( orderId));
    }
}
